new Vue({
    el:'#main',
    data:()=>({
        listdata:[],
        pageSize:10,
        page:1,
        type:false,
        is_must:false,
        update_at:false,
        drank:false,
        order:'type asc',
        typeText:'all',
        auth_ids:$('#adminauth_ids').text()
    }),
    methods:{
        getdata(){
            $('.loding').show()
            $.ajax({
                url:'/admin/buyterms/list',
                type:'post',
                data:{
                   page:this.page,
                   limit:10,
                   order:this.order,
                   typeText:this.typeText
                },
                success:(data)=>{
                    data = JSON.parse(data)
                    this.listdata = data.listdata
                    if(data.size) this.Resetnav(this.page,data.size)
                    $('.loding').hide()
                }
            })
        },
        Resetnav(pageCurrent, pageSum) {
            //数据总条数
            var myPageCount = pageSum;
            //一页显示多少条
            var myPageSize = this.pageSize;
            //总页数
            var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
            $.jqPaginator('#pagination', {
                totalPages: parseInt(countindex),
                //最多显示多少页
                visiblePages: 5,
                //默认显示第几页
                currentPage: pageCurrent,
                first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                all:'<li class="page"><a href="javascript:;">'+myPageCount+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                onPageChange:(num, type)=>{
                    if (type == "change") {
                        this.page=num
                        this.getdata()
                    }
                }
            });
        },
        requestDel(id){
            $.ajax({
                url:'/admin/buyterms/requestDel',
                type:'post',
                data:{id:id},
                success:(data)=>{
                    data = JSON.parse(data)
                    if(data.status==1){
                        this.getdata()
                    }
                    change_mes_type('.alert',data.status)
                    $('.alert').show()
                    $('.alert p').html(data.msg)
                }
            })
        },
        clickSort(type){
            if(this[type]){
                this.order = type+' asc'
            }else{
                this.order = type+' desc'
            }
            this[type] = !this[type]
            this.getdata()
        },
        getList(type){
            this.typeText = type
            this.getdata()
        }
       
    },
    mounted(){
        this.getdata()
        $("#terms_editModal").on("hidden.bs.modal", ()=>{
            if(localStorage.getItem("model"))
            this.getdata()
            localStorage.removeItem("model");
        });
    }
})